/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useRef } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import DragTable from '@/components/DragTable';
import ProTable from '@ant-design/pro-table';
import type { ActionType, ProColumns } from '@ant-design/pro-table';
import KbPreViewPopover from '@/components/KbPreViewPopover';
import { Input } from 'antd';
import { getLeaguePostData, pushToLeague } from '@/services/Inn/ChargeCheck';
import { Popconfirm } from 'antd';
import PreviewImage from '@/components/_pages/Finance/Receipt/PreviewImage';

const LeaguePost: React.FC = () => {
  const actionRef = useRef<ActionType>();

  const columns: ProColumns<Record<string, string>>[] = [
    {
      dataIndex: 'filter',
      hideInTable: true,
      renderFormItem: () => {
        return <Input placeholder='输入手机号查询' />;
      },
    },
    {
      title: 'ID',
      dataIndex: 'id',
      align: 'center',
      search: false,
    },
    {
      title: '微信昵称',
      dataIndex: 'wx_nick',
      align: 'center',
      search: false,
    },
    {
      title: '创建时间',
      dataIndex: 'create_time',
      align: 'center',
      search: false,
    },
    {
      title: '快递品牌',
      dataIndex: 'brand',
      align: 'center',
      search: false,
    },
    {
      title: '票量',
      dataIndex: 'delivery_num',
      align: 'center',
      search: false,
    },
    {
      title: '意向加盟区',
      dataIndex: 'location',
      align: 'center',
      search: false,
    },
    {
      title: '所属加盟商',
      dataIndex: 'agency_league',
      align: 'center',
      search: false,
    },
    {
      title: '姓名',
      dataIndex: 'name',
      align: 'center',
      search: false,
    },
    {
      title: '电话',
      dataIndex: 'phone',
      align: 'center',
      search: false,
      render: (_, record) => {
        const { phone, id } = record;
        return (
          <KbPreViewPopover
            text={phone}
            name='phone'
            api='/Inn/getLeaguePostDataById'
            queryData={{ id }}
          />
        );
      },
    },
    {
      title: '上传资料',
      dataIndex: 'picture_path',
      align: 'center',
      search: false,
      render: (val = '') => {
        return val != '-' ? (
          <PreviewImage src={val}>
            <a>图片链接</a>
          </PreviewImage>
        ) : (
          ''
        );
      },
    },
    {
      title: '推送',
      dataIndex: 'status',
      align: 'center',
      search: false,
      render: (_, record) => {
        const { status, agency_league, id } = record;
        if (status == '0') {
          if (!agency_league) {
            return (
              <Popconfirm
                title='确定推送？'
                onConfirm={pushToLeague.bind(null, {
                  id,
                  then: actionRef.current?.reload,
                })}
              >
                <a>推送</a>
              </Popconfirm>
            );
          } else {
            return '已推送';
          }
        } else {
          return '';
        }
      },
    },
  ];

  return (
    <PageContainer>
      <DragTable>
        <ProTable<Record<string, string>>
          actionRef={actionRef}
          rowKey='id'
          request={getLeaguePostData}
          pagination={{
            pageSize: 20,
            showQuickJumper: false,
            showSizeChanger: false,
          }}
          columns={columns}
          options={false}
          scroll={{ x: 1600 }}
          // headerTitle={
          //   <Button type='primary' icon={<DownloadOutlined />} onClick={downloadLeaguePostData}>
          //     导出下载
          //   </Button>
          // }
        />
      </DragTable>
    </PageContainer>
  );
};

export default LeaguePost;
